package com.qf.j2112.controller;

import com.qf.j2112.anno.JWTAnno;
import com.qf.j2112.po.TourArea;
import com.qf.j2112.po.TourSpot;
import com.qf.j2112.service.TourAreaService;
import com.qf.j2112.service.TourSpotService;
import com.qf.j2112.vo.ActionResultVO;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api")
@CrossOrigin
public class TourSpotController {

    @Resource
    private TourSpotService tourSpotService;

    @Resource
    private TourAreaService tourAreaService;

    //获取一个景区的的全部景点集合
    @JWTAnno(name = "用户端获取景区的全部景点集合")
    @GetMapping("/spots")
    public ActionResultVO listAllSpot(){
        ActionResultVO vo=null;
        List<TourSpot> spotList = tourSpotService.findAll();
        if (!ObjectUtils.isEmpty(spotList)){
            for(TourSpot s:spotList) {
                TourArea area=tourAreaService.findOneByAid(s.getAid());
                s.setParentName(area.getAname());
            }
            vo=new ActionResultVO(200,"查询景点成功",spotList);
        }else {
            vo=new ActionResultVO(-200,"查询景点失败",null);
        }
        return vo;
    }
}
